﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Furiant.Figment.Core
{
    public abstract class GameObject : IGameObject
    {
        #region Fields

        private readonly int _id;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new instance of GameObject.
        /// </summary>
        /// <param name="uniqueIdProvider">A method which generates a unique Id for this instance. If null, the default provider will be used.</param>
        protected GameObject(Func<IGameObject, int> uniqueIdProvider)
        {
            _id = uniqueIdProvider != null ? uniqueIdProvider(this) : GetId();
        }

        /// <summary>
        /// Creates a new instance of GameObject using the default unique Id provider.
        /// </summary>
        protected GameObject() : this(null) { }

        #endregion

        #region Properties

        /// <summary>
        /// The unique identifier for this instance.
        /// </summary>
        public virtual int Id { get { return _id; } }

        #endregion

        #region Methods

        protected int GetId()
        {
            return FigmentData.Instance.GenerateGameObjectId(this);
        }

        #endregion
    }
}
